package ca.kooki.codesnippet;

import junit.framework.Assert;

import org.junit.Test;

public class DescriptionTest 
{

  
  @Test
  public void Constructor()
  {
    Description description = new Description("t","k1 k2 k3");
    
    Assert.assertEquals("t",description.getTitle());
    Assert.assertEquals("k1 k2 k3",description.getKeywords());
    
    String[] allKeywords = description.getKeywordList();
    Assert.assertEquals(3, allKeywords.length);
    Assert.assertEquals("k1", allKeywords[0]);
    Assert.assertEquals("k2", allKeywords[1]);
    Assert.assertEquals("k3", allKeywords[2]);
    
  }
  
  @Test
  public void IgnoreKeywordWhiteSpace()
  {
    Description description = new Description("t"," k1   k2 k3  ");

    String[] allKeywords = description.getKeywordList();
    Assert.assertEquals(3, allKeywords.length);
    Assert.assertEquals("k1", allKeywords[0]);
    Assert.assertEquals("k2", allKeywords[1]);
    Assert.assertEquals("k3", allKeywords[2]);

  }
  
  @Test
  public void ToStringShowsAll()
  {
    Description description = new Description("t","k");
    Assert.assertEquals("t;k;", description.toString());
    
  }
  
  @Test
  public void NotEqualsNull()
  {
    Description description = new Description("t","k");
    Assert.assertFalse(description.equals(null));
    Assert.assertFalse(description.equals("blah"));
  }

  @Test
  public void NotEqualsWrongData()
  {
    Description description = new Description("t","k");
    Description compareTo = null;
    
    compareTo = new Description("t1","k");
    Assert.assertFalse(description.equals(compareTo));

    compareTo = new Description("t","k1");
    Assert.assertFalse(description.equals(compareTo));

  }

  @Test
  public void EqualsAllTheSame()
  {
    Description description = new Description("t","k");
    Description compareTo = new Description("t","k");
    Assert.assertTrue(description.equals(compareTo));
  }

  @Test
  public void ContainsEmpty()
  {
    Description description = new Description("t","k1 k2");
    Assert.assertEquals(true, description.contains(""));
    Assert.assertEquals(true, description.contains(null));
  }

  @Test
  public void Contains()
  {
    Description description = new Description("t","k1 k2");
    Assert.assertEquals(true, description.contains("k1"));
    Assert.assertEquals(true, description.contains("k2"));
    Assert.assertEquals(false, description.contains("k3"));
    Assert.assertEquals(false, description.contains("k"));
  }

  @Test
  public void MultipleEntries()
  {
    Description description = new Description("t","k1 k2");
    Assert.assertEquals(true, description.contains("k1 k2"));
    Assert.assertEquals(true, description.contains("k2 k1"));
    Assert.assertEquals(true, description.contains("k1 k3"));
    Assert.assertEquals(false, description.contains("k3 k4"));
  }

}
